<template>
    <div>
        <el-form ref="formData" v-loading="formLoading" :model="formData" label-width="100px">
                <!--列表-->
                <el-table v-loading="formLoading" border height="400" :data="formData.enterDetails"
                    tooltip-effect="dark" class="table-info">
                    <el-table-column prop="reagentConsumableNum" label="编号" min-width="60" />
                    <el-table-column prop="name" label="名称" min-width="70" />
                    <el-table-column prop="volume" label="规格" min-width="90" />,
                    <el-table-column prop="attributeName" label="分类" min-width="60" />
                    <el-table-column prop="warehouseName" label="库位" width="160" />
                    <el-table-column prop="quantity" label="入库数量" min-width="100" />
                    <el-table-column prop="validTime" label="有效期" min-width="160" />
                </el-table>
            </el-form>
            <!--分页-->
            <BasePagination v-if="readOnly" class="pagination-component" :total="total"
                :current-page="pageInfo.pageIndex" :page-count="pageCount" @changePage="changePage" />
    </div>
</template>
<script>
import {
  AuditEnter,
  ReagentEnterGet
} from "./api/ReagentConsumable/ReagentConsumableAudit";
export default {
  name: "AuditReagentConsumableDialog",
  components: {},
  props: {
    readOnly: {
      type: Boolean,
      default: false,
    },
    fromSource: { // 数据来源。例：价格核酸或者是数据录入等。。。
      type: String,
      default: "",
    },
    row: { // 所选择的数据
      type: Object,
      default: () => { },
    },
    editId: { // 审核数据的数据Id
      type: String,
      default: "",
    },
  },
  data() {
    return {
      formLoading: false,
      pageInfo: {
        pageIndex: 1,
        pageSize: 9999
      },
      pageCount: 0,
      total: 0,
      formData: {
        dataType: "",
        enterDetails: [],
      },
    };
  },
  created() {
    this.init();
  },
  methods: {
    // 初始化
    async init() {
      // 获取列表 每次打开获取 防止数据不是最新
      this.formLoading = true;
      if (this.editId) {
        // 获取入库信息
        ReagentEnterGet({ id: this.editId, ...this.pageInfo })
          .then((res) => {
            const params = {
              dataType: res.data.dataType,
              enterId: res.data.enterId,
              enterNum: res.data.enterNum,
              enterDetails: res.data.dataList.map(item => {
                return {
                  ...item,
                  volume: item.volume,
                  attributeName: item.attributeName,
                }
              })
            }
            this.formData = params
            this.total = res.data.total;
          })
          .finally(() => {
            this.formLoading = false;
          });
      } else {
        this.formLoading = false;
        this.total = 0;
      }
    },
    innerPass(obj) {
      const requestData = JSON.parse(JSON.stringify(obj));
      requestData.AuditStatus = 30;
      AuditEnter(requestData)
        .then((res) => {
          if (res.code === 400) {
            this.$message.error(res.msg);
            return;
          }
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
    innerReject(obj) {
      const requestData = JSON.parse(JSON.stringify(obj));
      requestData.AuditStatus = 40;
      AuditEnter(requestData)
        .then((res) => {
          if (res.code === 400) {
            this.$message.error(res.msg);
            return;
          }
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
  },
};
</script>
